package com.hkzhao.reportingsystem.service.impl;

import com.hkzhao.reportingsystem.common.utils.JwtTokenUtil;
import com.hkzhao.reportingsystem.mbg.mapper.AdminuserMapper;
import com.hkzhao.reportingsystem.mbg.mapper.DoctorMapper;
import com.hkzhao.reportingsystem.mbg.mapper.ManagerMapper;
import com.hkzhao.reportingsystem.mbg.mapper.UserPermissionMapper;
import com.hkzhao.reportingsystem.mbg.model.*;
import com.hkzhao.reportingsystem.service.AdminUserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class AdminUserServiceImpl implements AdminUserService {
    private static final Logger LOGGER = LoggerFactory.getLogger(AdminUserServiceImpl.class);
    @Autowired(required = false)
    private AdminuserMapper adminuserMapper;
    @Autowired(required = false)
    private UserPermissionMapper userPermissionMapper;
    @Autowired(required = false)
    private DoctorMapper doctorMapper;
    @Autowired(required = false)
    private ManagerMapper managerMapper;
    @Override
    public List<UserPermission> getPermissionList(String token_id) {
        UserPermissionExample userPermissionExample = new UserPermissionExample();
        userPermissionExample.createCriteria().andTokenIdEqualTo(token_id);
        List<UserPermission> list = userPermissionMapper.selectByExample(userPermissionExample);
        if(list!=null)
            return list;
        return null;
    }

    @Override
    public String getPassword(String username) {
        AdminuserExample adminuserExample = new AdminuserExample();
        adminuserExample.createCriteria().andUsernameEqualTo(username);
        List<Adminuser> adminuser =adminuserMapper.selectByExample(adminuserExample);
        if(adminuser!=null&&adminuser.size()>0)
        {
           if(adminuser.get(0).getPosition().equals("1"))
           {
               return managerMapper.selectByPrimaryKey(username).getPassword();
           }
            else if(adminuser.get(0).getPosition().equals("0"))
                return doctorMapper.selectByPrimaryKey(username).getPassword();
            else
           {
               return "";}
        }
        return "";
    }

    @Override
    public Adminuser getAdminUserByusername(String username) {
            AdminuserExample adminuserExample = new AdminuserExample();
            adminuserExample.createCriteria().andUsernameEqualTo(username);
            List<Adminuser> list = adminuserMapper.selectByExample(adminuserExample);
            if(list!=null&&list.size()>0)
                return list.get(0);
            return null;
    }
}
